/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package GUI;


import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.sql.SQLException;
import java.util.ArrayList;
import javax.swing.JOptionPane;
import javax.swing.table.TableRowSorter;
import persistencia.BaseDatosConsultasExternas;

/**
 *
 * @author jony
 */
public class JPExportarHistorialClinico extends javax.swing.JPanel {

    
    private Boolean DatosEnLaTabla = false;
    
    
    
    
    
    /**
     * Creates new form JPExportarHistorialClinico
     */
    
   
    
    public JPExportarHistorialClinico() {
        initComponents();
        
         //Pongo false para esconder los paneles de abajo.
         jpCE.setVisible(false);
         jpIngresos.setVisible(false);
         jpIntervencion.setVisible(false);
         jpUrgencias.setVisible(false);

        //Bloqueo la escritura en los JTextFields.
        jtfNombrePaciente.setEditable(false);
       
        
            
        
        
        
        
        
/////////////////////////////////////////       BOTÓN CONSULTAS EXTERNAS       
           jbCE.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {
                  jpCE.setVisible(true);
                  jpIngresos.setVisible(false);
                  jpIntervencion.setVisible(false);
                  jpUrgencias.setVisible(false);
                  
                  jtfNombrePaciente.setEditable(true);
                  jtfNombrePaciente.setText(null);
            }
        });
        
//////////////////////////////////////////////////BOTÓN URGENCIAS           
           
           
                jbUrgencias.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {
                  jpCE.setVisible(false);
                  jpIngresos.setVisible(false);
                  jpIntervencion.setVisible(false);
                  jpUrgencias.setVisible(true);
                  
                  jtfNombrePaciente.setEditable(true);
                  jtfNombrePaciente.setText(null);
            }
        });
           
           
/////////////////////////////////////////    BOTÓN INTERVENCION        
                jbIntervencion.addMouseListener(new MouseAdapter() {
                  BaseDatosConsultasExternas BBDD;
            @Override
            public void mouseClicked(MouseEvent me) {
                
           jbIntervencion.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {
                BBDD = null;
                try {
                    BBDD = new BaseDatosConsultasExternas();
                    mostrarModelos();
                    DatosEnLaTabla = true;
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(getParent(), "BBDD no disponible", "ERROR", JOptionPane.ERROR_MESSAGE);
                } catch (ClassNotFoundException ex) {
                    JOptionPane.showMessageDialog(getParent(), "Drivers no disponibles", "ERROR", JOptionPane.ERROR_MESSAGE);
                } finally {
                    if (BBDD != null) {
                        try {
                            BBDD.closeConnection();
                        } catch (SQLException ex) {
                            JOptionPane.showMessageDialog(getParent(), "Drivers no disponibles", "ERROR", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                }
            }
        });
                
                
                  jpCE.setVisible(false);
                  jpIngresos.setVisible(false);
                  jpIntervencion.setVisible(true);
                  jpUrgencias.setVisible(false);
                  
                  jtfNombrePaciente.setEditable(true);
                  jtfNombrePaciente.setText(null);
            }
        });
                
                
//////////////////////////////////////////////////// BOTÓN INGRESOS            
                
             jbIngresos.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent me) {
                  jpCE.setVisible(false);
                  jpIngresos.setVisible(true);
                  jpIntervencion.setVisible(false);
                  jpUrgencias.setVisible(false);
                  
                  jtfNombrePaciente.setEditable(true);
                  jtfNombrePaciente.setText(null);
            }
        });   
           
           
           
           
           
    }////////////////////////////FIN
    
             private void mostrarModelos() {
                 BaseDatosConsultasExternas BBDD;
        BBDD = null;
        try {
            BaseDatosConsultasExternas dbm = new BaseDatosConsultasExternas();
            dbm.getCE();
        } catch (ClassNotFoundException ex) {
            JOptionPane.showMessageDialog(getParent(), "Drivers no disponibles", "ERROR", JOptionPane.ERROR_MESSAGE);
        } catch (SQLException ex) {
            JOptionPane.showMessageDialog(getParent(), "BBDD no disponible", "ERROR", JOptionPane.ERROR_MESSAGE);
        } finally {
            if (BBDD != null) {
                try {
                    BBDD.closeConnection();
                } catch (SQLException ex) {
                    JOptionPane.showMessageDialog(getParent(), "BBDD no disponible", "ERROR", JOptionPane.ERROR_MESSAGE);
                }
            }
        }
    }
    

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jLabel2 = new javax.swing.JLabel();
        jbExportarDatos = new javax.swing.JButton();
        jtfNombrePaciente = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jToolBar1 = new javax.swing.JToolBar();
        jbIntervencion = new javax.swing.JButton();
        jbIngresos = new javax.swing.JButton();
        jbCE = new javax.swing.JButton();
        jbUrgencias = new javax.swing.JButton();
        jpIntervencion = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        jtIntervencion = new javax.swing.JTable();
        jpIngresos = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jtIngresos = new javax.swing.JTable();
        jpUrgencias = new javax.swing.JPanel();
        jScrollPane3 = new javax.swing.JScrollPane();
        jtUrgencias = new javax.swing.JTable();
        jpCE = new javax.swing.JPanel();
        jScrollPane4 = new javax.swing.JScrollPane();
        jtCE = new javax.swing.JTable();

        jLabel2.setText("jLabel2");

        jbExportarDatos.setText("Buscar por id");

        jLabel1.setText("Escribe el nombre del paciente: ");

        jToolBar1.setRollover(true);

        jbIntervencion.setText("Intervención");
        jbIntervencion.setFocusable(false);
        jbIntervencion.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbIntervencion.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jbIntervencion);

        jbIngresos.setText("Ingresos");
        jbIngresos.setFocusable(false);
        jbIngresos.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jbIngresos.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToolBar1.add(jbIngresos);

        jbCE.setText("Consultas Externas");
        jToolBar1.add(jbCE);

        jbUrgencias.setText("Urgencias");
        jToolBar1.add(jbUrgencias);

        jpIntervencion.setBackground(new java.awt.Color(153, 153, 153));
        jpIntervencion.setForeground(new java.awt.Color(153, 153, 153));
        jpIntervencion.setLayout(new java.awt.CardLayout());

        jtIntervencion.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "ID", "Fecha", "Nº Quirofano", "Especialidad"
            }
        ));
        jScrollPane1.setViewportView(jtIntervencion);

        jpIntervencion.add(jScrollPane1, "card2");

        jpIngresos.setBackground(new java.awt.Color(255, 102, 204));
        jpIngresos.setLayout(new java.awt.CardLayout());

        jtIngresos.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "id Ingreso", "Fecha Ingreso", "Fecha Alta", "id Paciente"
            }
        ));
        jScrollPane2.setViewportView(jtIngresos);

        jpIngresos.add(jScrollPane2, "card2");

        jpUrgencias.setBackground(new java.awt.Color(51, 204, 255));
        jpUrgencias.setLayout(new java.awt.CardLayout());

        jtUrgencias.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null},
                {null, null, null, null}
            },
            new String [] {
                "id Urgencias", "Fecha Urgencias", "Fecha Alta", "id Paciente"
            }
        ));
        jScrollPane3.setViewportView(jtUrgencias);

        jpUrgencias.add(jScrollPane3, "card2");

        jpCE.setBackground(new java.awt.Color(204, 255, 51));
        jpCE.setForeground(new java.awt.Color(153, 153, 0));
        jpCE.setLayout(new java.awt.CardLayout());

        jtCE.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null},
                {null, null, null, null, null, null}
            },
            new String [] {
                "idConsulta", "Fecha", "Hora Entrada", "Hora Salida", "Especialidad", "id Proceso Asistencial"
            }
        ));
        jScrollPane4.setViewportView(jtCE);

        jpCE.add(jScrollPane4, "card2");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGap(203, 203, 203))
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jpIntervencion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jpCE, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jpIngresos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jpUrgencias, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jtfNombrePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, 108, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jbExportarDatos)))
                .addContainerGap(647, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jToolBar1, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jtfNombrePaciente, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jbExportarDatos))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(jpIngresos, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpCE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpUrgencias, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jpIntervencion, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap(14, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JButton jbCE;
    private javax.swing.JButton jbExportarDatos;
    private javax.swing.JButton jbIngresos;
    private javax.swing.JButton jbIntervencion;
    private javax.swing.JButton jbUrgencias;
    private javax.swing.JPanel jpCE;
    private javax.swing.JPanel jpIngresos;
    private javax.swing.JPanel jpIntervencion;
    private javax.swing.JPanel jpUrgencias;
    private javax.swing.JTable jtCE;
    private javax.swing.JTable jtIngresos;
    private javax.swing.JTable jtIntervencion;
    private javax.swing.JTable jtUrgencias;
    private javax.swing.JTextField jtfNombrePaciente;
    // End of variables declaration//GEN-END:variables
}
